package com.example.demo.config;

import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
import org.noear.solon.cache.jedis.RedisCacheService;
import org.noear.solon.data.cache.CacheService;
import org.noear.solon.data.cache.CacheTagsService;
import org.noear.solon.data.cache.CacheTagsServiceImpl;
import org.noear.solon.data.cache.impl.JavabinSerializer;
import org.noear.solon.data.cache.impl.JsonSerializer;

import java.util.Properties;

/**
 * @author airhead
 */
@Configuration
public class CacheConfig {
    @Bean(typed = true)
    public CacheService defaultCache(@Inject("${demo.cache}") Properties props) {
        RedisCacheService cacheService = new RedisCacheService(props);
        cacheService.enableMd5key(false);
//        cacheService.serializer(JavabinSerializer.instance);
        cacheService.serializer(JsonSerializer.instance);
        return cacheService;
    }

    @Bean
    public CacheTagsService defaultCache(@Inject CacheService cacheService) {
        return new CacheTagsServiceImpl(cacheService);
    }
}
